﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace GeoFly
{
    //栅格图层中间结果输出标志类
public class MidGridResultOut
{
	//输出结果标志
    /// <summary>
    /// 输出结果路径
    /// </summary>
	public string	OutputPath;					//输出结果路径
    /// <summary>
    /// 输出起始日期
    /// </summary>
	public DateTime OutputStartDate;					//输出起始日期
    /// <summary>
    /// 输出结束日期
    /// </summary>
	public DateTime	OutputEndDate;					//输出结束日期
    /// <summary>
    /// 降雨量
    /// </summary>
	public bool	iPcp;							//降雨量	
    /// <summary>
    /// 最高气温
    /// </summary>
	public bool	iTempMax;						//最高气温
    /// <summary>
    /// 最低气温
    /// </summary>
	public bool	iTempMin;						//最低气温
    /// <summary>
    /// 平均气温
    /// </summary>
	public bool	iTempMean;						//平均气温
    /// <summary>
    /// 太阳辐射
    /// </summary>
	public bool	iSlr;							//太阳辐射
    /// <summary>
    /// 相对湿度
    /// </summary>
	public bool	iHmd;							//相对湿度
    /// <summary>
    /// 平均风速
    /// </summary>
	public bool	iWnd;							//平均风速
    /// <summary>
    /// 潜在蒸散量
    /// </summary>
	public bool	iPET;							//潜在蒸散量
    /// <summary>
    /// 实际蒸散量
    /// </summary>
	public bool	iAET;							//实际蒸散量
    /// <summary>
    /// 冠层截留
    /// </summary>
	public bool	iCI;							//冠层截留
    /// <summary>
    /// 干旱指数
    /// </summary>
	public bool	iAI;							//干旱指数
    /// <summary>
    /// 栅格汇流结果
    /// </summary>
	public bool	iRouteOut;						//栅格汇流结果
    /// <summary>
    /// 地表径流
    /// </summary>
	public bool	iSurfQ;							//地表径流
    /// <summary>
    /// 壤中流
    /// </summary>
	public bool	iLatQ;							//壤中流
    /// <summary>
    /// 地下径流
    /// </summary>
	public bool	iBaseQ;							//地下径流
    /// <summary>
    /// 时段下渗率
    /// </summary>
	public bool	iInfilRate;						//时段下渗率
    /// <summary>
    /// 栅格产流类型
    /// </summary>
	public bool	iWaterYieldType;				//栅格产流类型
    /// <summary>
    /// 降雪量
    /// </summary>
	public bool	iSnowWater;						//降雪量
    /// <summary>
    /// 土壤剖面含水量
    /// </summary>
	public bool	iProfileSoilWater;				//土壤剖面含水量
    /// <summary>
    /// 土层剖面平均含水量
    /// </summary>
	public bool	iAvgSoilWater;					//土层剖面平均含水量

	public bool	bOutDate;					

	//输出结果图层
    /// <summary>
    /// 冠层截留
    /// </summary>
	public GridLayer	m_CI;						//冠层截留
    /// <summary>
    /// 冠层截留赤字
    /// </summary>
	public GridLayer	m_CIDefict;					//冠层截留赤字
    /// <summary>
    /// 到达地表的净雨
    /// </summary>
	public GridLayer	m_NetPcp;					//到达地表的净雨
    /// <summary>
    /// 实际蒸散发
    /// </summary>
	public GridLayer	m_AET;						//Actual Evapotranspiration
    /// <summary>
    ///干旱指数
    /// </summary>
	public GridLayer	m_AI;						//Arid Index
    /// <summary>
    /// 降雪量
    /// </summary>
    public GridLayer m_SnowWater;				//降雪量
    /// <summary>
    /// 栅格总产流
    /// </summary>
    public GridLayer m_GridTotalQ;				//栅格总产流
    /// <summary>
    /// 栅格地表径流
    /// </summary>
    public GridLayer m_GridSurfQ;
    /// <summary>
    /// 栅格壤中流
    /// </summary>
    public GridLayer m_GridLateralQ;
    /// <summary>
    /// 栅格地下径流（基流）
    /// </summary>
    public GridLayer m_GridBaseQ;
    /// <summary>
    /// 栅格汇流结果
    /// </summary>
    public GridLayer m_GridRoutingQ;				//栅格汇流结果
    /// <summary>
    /// 产流计算类型
    /// </summary>
	public GridLayer	m_GridWaterYieldType;		//产流计算类型
    /// <summary>
    /// 土壤剖面含水量
    /// </summary>
	public GridLayer	m_SoilProfileWater;			//土壤剖面含水量
    /// <summary>
    /// 土层平均含水量
    /// </summary>
	public GridLayer	m_SoilAvgWater;				//土层平均含水量


	public void	ResetContent()
    {
        OutputPath = "c:\\debam\\output";
	    OutputStartDate  =Convert.ToDateTime( "1990-1-1");
	    OutputEndDate = Convert.ToDateTime("1990-1-1");
	
    }
    /// <summary>
    /// 读入中间参数保存标志文件
    /// </summary>
    /// <param name="FileName"></param>
	public void	ReadMidOutFile(string FileName)
    {
        
            ResetContent();
            if (FileName == null)
                return;
            if (!File.Exists(FileName))
            {
                throw new Exception("文件"+FileName+"不存在!");
            }

            List<string> saValue = MatrixFuncs.FileRead(FileName);

            string[] saOut = saValue[1].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.OutputPath = saOut[1];

            saOut = saValue[2].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.OutputStartDate =Convert.ToDateTime( saOut[1]);

            saOut = saValue[3].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.OutputEndDate =Convert.ToDateTime(  saOut[1]);

            saOut = saValue[4].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iPcp =Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[5].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iTempMax = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[6].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iTempMin = Convert.ToBoolean(Convert.ToInt16(saOut[1]));


            saOut = saValue[7].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iTempMean = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[8].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iSlr = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[9].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iHmd = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[10].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iWnd = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[11].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iPET = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[12].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iAET = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[13].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iCI = Convert.ToBoolean(Convert.ToInt16(saOut[1]));


            saOut = saValue[14].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iSnowWater = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[15].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iAI = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[16].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iRouteOut = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[17].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iSurfQ = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[18].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iLatQ = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[19].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iBaseQ = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[20].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iInfilRate = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[21].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iWaterYieldType = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[22].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iProfileSoilWater = Convert.ToBoolean(Convert.ToInt16(saOut[1]));

            saOut = saValue[23].Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            this.iAvgSoilWater = Convert.ToBoolean(Convert.ToInt16(saOut[1]));
        }
    /// <summary>
    /// 输出、保存中间参数保存标志文件;
    /// </summary>
    /// <param name="FileName"></param>
    /// <returns></returns>
    public void WriteMidOutFile(string FileName)
    {
        StreamWriter sw = new StreamWriter(FileName);
        sw.WriteLine("    DCBAM Model Input Parameters:\t"+DateTime.Now.ToString());

        sw.WriteLine("输出图层目录\t"+this.OutputPath);

        sw.WriteLine("起始时间\t" + this.OutputStartDate);

        sw.WriteLine("结束日期\t" + this.OutputEndDate);

        sw.WriteLine("降雨量\t" + Convert.ToInt16(this.iPcp));

        sw.WriteLine("最高气温\t" + Convert.ToInt16(this.iTempMax));

        sw.WriteLine("最低气温\t" + Convert.ToInt16(this.iTempMin));

        sw.WriteLine("平均气温\t" + Convert.ToInt16(this.iTempMean));

        sw.WriteLine("太阳辐射\t" + Convert.ToInt16(this.iSlr));

        sw.WriteLine("相对湿度\t" + Convert.ToInt16(this.iHmd));



        sw.WriteLine( "平均风速\t"+ Convert.ToInt16(this.iWnd));
        

        sw.WriteLine( "潜在蒸散量\t"+ Convert.ToInt16(this.iPET));
        

        sw.WriteLine( "实际蒸散量\t"+ Convert.ToInt16(this.iAET));
        

        sw.WriteLine( "冠层截留\t"+ Convert.ToInt16(this.iCI));
        

        sw.WriteLine( "雪水当量\t"+ Convert.ToInt16(this.iSnowWater));
        

        sw.WriteLine( "干旱指数\t"+ Convert.ToInt16(this.iAI));
        

        sw.WriteLine( "栅格汇流演算结果\t"+ Convert.ToInt16(this.iRouteOut));
        

        sw.WriteLine( "时段地表径流\t"+ Convert.ToInt16(this.iSurfQ));
        

        sw.WriteLine( "时段壤中径流\t"+ Convert.ToInt16(this.iLatQ));
        

        sw.WriteLine( "时段地下径流\t"+ Convert.ToInt16(this.iBaseQ));
        

        sw.WriteLine( "时段土壤下渗率\t"+ Convert.ToInt16(this.iInfilRate));
        

        sw.WriteLine( "栅格产流类型\t"+ Convert.ToInt16(this.iWaterYieldType));
        

        sw.WriteLine( "土层剖面含水量\t"+ Convert.ToInt16(this.iProfileSoilWater));
        

        sw.WriteLine( "土层平均含水量\t"+ Convert.ToInt16(this.iAvgSoilWater));
        sw.Close();

        
    }
};
}
